package com.flong.spring.filter;

import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

import java.io.IOException;

/**
 * @Author:liangjl
 * @Date: 2020/6/10-19:21
 * @Eamil:jilongliang@sina.com
 * @Description:
 */
public class MyFilter implements TypeFilter {


    /**
     * @param metadataReader        读取到的当前正在扫描的类信息
     * @param metadataReaderFactory 可以获取其他任何类信息
     * @return
     * @throws IOException
     */
    @Override
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {

        //获取当前类注解的信息
        AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();

        //获取当前正在扫描类的类信息
        ClassMetadata classMetadata = metadataReader.getClassMetadata();
        //获取当前类资源(类的路径)
        Resource resource = metadataReader.getResource();

        String className = classMetadata.getClassName();

        if (className.contains("er")) {
            //System.out.println("包含er的类：" + className);
            return true;
        }else{
            return false;

        }
    }
}
